package com.beici.vueblogapp.service.serivceImp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.beici.vueblogapp.mapper.siteMapper;
import com.beici.vueblogapp.model.blogSite;
import com.beici.vueblogapp.model.results;
import com.beici.vueblogapp.service.siteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class siteServiceImpl implements siteService {

    @Autowired
    private siteMapper siteService;

    @Override
    public results getSiteAll() {
        results result = new results();
        List<blogSite> blogSites = siteService.selectList(null);
        if (blogSites !=null){
            result.setCode(200);
            result.setMessage("获取成功");
            result.setObject(blogSites);
            return result;
        }
        result.setCode(500);
        result.setMessage("获取失败");
        result.setObject("");
        return result;
    }

    @Override
    public results getThroughSiteAll() {
        results result = new results();
        List<blogSite> blogSites = siteService.selectList(new QueryWrapper<blogSite>().eq("site_code",1));
        if (blogSites !=null){
            result.setCode(200);
            result.setMessage("获取成功");
            result.setObject(blogSites);
            return result;
        }
        result.setCode(500);
        result.setMessage("获取失败");
        result.setObject("");
        return result;
    }

    @Override
    public results commitSity(blogSite sit) {
        results result = new results();
        int insert = siteService.insert(sit);
        if (insert>0){
            result.setCode(200);
            result.setMessage("提交成功");
            result.setObject(true);
            return result;
        }
        result.setCode(500);
        result.setMessage("提交失败");
        result.setObject(false);
        return result;
    }

    @Override
    public results updateSityCode(Integer id, Integer code) {
        results result = new results();
        blogSite sit = new blogSite();
        sit.setSiteId(id);
        sit.setSiteCode(code);
        int i = siteService.updateById(sit);
        if (i>0){
            result.setCode(200);
            result.setMessage("提交成功");
            result.setObject(true);
            return result;
        }
        result.setCode(500);
        result.setMessage("提交失败");
        result.setObject(false);
        return result;
    }
}
